#pragma once

#include <zenox/pragma.hpp>
#include <zenox/unicode.hpp>
#include <string_view>
#include <string>
#include <unordered_map>
#include <set>

namespace zenox {

struct LocalizationEngine {
    std::multiset<std::string> keys;
    std::multiset<std::string> vals;
    std::unordered_map<std::string_view, std::string_view> dict;

    static ZENO_CONST_FN LocalizationEngine &instance();

    void load_from_file(std::string dictpath);

    // translate a given string literial
    ZENO_CONST_FN std::string_view lookup(std::string_view key) const {
        auto it = dict.find(key);
        if (it != dict.end()) {
            return it->second;
        } else {
            return key;
        }
    }
};

inline namespace localization_literials {

inline std::string operator""_zenos(const char *s, size_t len) {
    return std::string(LocalizationEngine::instance().lookup({s, len}));
}

inline std::string_view operator""_zenosv(const char *s, size_t len) {
    return LocalizationEngine::instance().lookup({s, len});
}

inline const char *operator""_zenocstr(const char *s, size_t len) {
    return LocalizationEngine::instance().lookup({s, len}).data();
}

inline std::u32string operator""_zenos(const char32_t *s, size_t len) {
    return u8tou32(LocalizationEngine::instance().lookup(u32tou8({s, len})));
}

}

}

using namespace zenox::localization_literials;

// usage:
// "This is a message"_zenosv
